<template>
  <div class="mod-config">
    <basic-container>
      <navigationZDRW :sign="{ a: false, b: true, c: false }"></navigationZDRW>
      <div v-if="showZhong == 1" class="boxsty zhiBiao">
        <div :height="searchheight">
          <span
            style="float: right; margin-top: -30px; cursor: pointer"
            @click="searchchangeadvanced"
            >{{ searchadvanced ? "查询条件收起" : "查询条件展开" }}
            <i
              :class="
                searchadvanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'
              "
            />
          </span>
          <div v-show="searchadvanced">
            <el-form
              :inline="true"
              :model="dataForm"
              @keyup.enter.native="getDataList()"
              class="form-inline"
            >
              <el-form-item label="发起名称">
                <el-input
                  v-model="dataForm.faqiName"
                  placeholder="发起名称"
                  :clearable="true"
                  style="width: 150px"
                ></el-input>
              </el-form-item>
              <el-form-item label="被考核人姓名">
                <el-input
                  v-model="dataForm.ryName"
                  placeholder="被考核人姓名"
                  :clearable="true"
                  style="width: 150px"
                ></el-input>
              </el-form-item>
              <el-form-item label="被考核人岗位">
                <el-input
                  v-model="dataForm.userZw"
                  placeholder="被考核人岗位"
                  :clearable="true"
                  style="width: 150px"
                ></el-input>
              </el-form-item>
              <el-form-item>
                <el-button
                  icon="el-icon-search"
                  type="primary"
                  class="marginLeft"
                  @click="getDataList(1)"
                  >检索
                </el-button>
              </el-form-item>
            </el-form>
          </div>
        </div>
        <div class="border-top-theme">
          <div class="mt10" style="overflow: hidden">
            <div style="float: right">
              <el-button type="primary" plain @click="sent()">批量发起</el-button>
            </div>
          </div>
        </div>
        <el-table
          style="width: 100%; margin-top: 10px"
          :data="dataList"
          border
          ref="table"
          v-loading="dataListLoading"
          v-if="tableShow"
        >
          <el-table-column
            type="selection"
            width="55"
            header-align="center"
            align="center"
            :selectable="checkboxSelect"
          ></el-table-column>
          <el-table-column
            type="index"
            width="80"
            header-align="center"
            align="center"
            label="序号"
          ></el-table-column>
          <el-table-column
            prop="faqiName"
            header-align="center"
            align="center"
            width="200"
            show-overflow-tooltip
            label="发起名称"
          >
          </el-table-column>
          <el-table-column
            prop="userName"
            header-align="center"
            align="center"
            min-width="120"
            show-overflow-tooltip
            label="被考核人编号"
          >
          </el-table-column>
          <el-table-column
            prop="ryName"
            header-align="center"
            align="center"
            min-width="120"
            show-overflow-tooltip
            label="被考核人姓名"
          >
            <template slot-scope="scope">
              <span
                @click="preview(scope.row)"
                style="color: #0e258c; cursor: pointer"
                >{{ scope.row.ryName }}</span
              >
            </template>
          </el-table-column>
          <el-table-column
            prop="userDeptName"
            header-align="center"
            align="center"
            min-width="120"
            show-overflow-tooltip
            label="被考核人单位"
          >
          </el-table-column>
          <el-table-column
            prop="userZj"
            header-align="center"
            align="center"
            label="被考核人职级"
            v-if="showType == 2"
            min-width="180"
            show-overflow-tooltip
          >
            <template slot="header">
              <el-tooltip placement="top" content="点击切换至被考核人岗位">
                <span
                    ><i
                      @click="switchBtn(1)"
                      class="el-icon-refresh"
                      style="margin-right: 20px"
                    ></i
                    >被考核人职级</span
                  >
              </el-tooltip>
            </template>
          </el-table-column>
          <el-table-column
            prop="userZw"
            header-align="center"
            align="center"
            min-width="180"
            show-overflow-tooltip
            label="被考核人岗位"
            v-if="showType == 1"
          >
            <template slot="header">
              <el-tooltip placement="top" content="点击切换至被考核人职级">
                <span
                    ><i
                      @click="switchBtn(2)"
                      class="el-icon-refresh"
                      style="margin-right: 20px"
                    ></i
                    >被考核人岗位</span
                  >
              </el-tooltip>
            </template>
          </el-table-column>
          <el-table-column
            prop="rwCount"
            header-align="center"
            align="center"
            min-width="100"
            show-overflow-tooltip
            label="任务数量"
          >
          </el-table-column>
          <el-table-column
            prop="userLx"
            header-align="center"
            align="center"
            width="100"
            label="发起类型"
          >
          <template scope="scope">
            <span v-if="scope.row.userLx == '1'">总部发起</span>
            <span v-if="scope.row.userLx == '2'">总部自拟</span>
            <span v-if="scope.row.userLx == '3'">部门自拟</span>
          </template>
          </el-table-column>
          <el-table-column
            prop="stateExplain"
            header-align="center"
            align="center"
            min-width="120"
            label="任务状态"
          >
          </el-table-column>
        </el-table>
        <div class="avue-crud__pagination">
          <el-pagination
            @size-change="sizeChangeHandle"
            @current-change="currentChangeHandle"
            :current-page="pageIndex"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="pageSize"
            :total="totalPage"
            background
            layout="total, sizes, prev, pager, next, jumper"
          >
          </el-pagination>
        </div>
      </div>
      <!--          任务自评/发起-->
      <zdzpForm
        v-if="showZhong == 2"
        ref="renwufaqi"
        :titleForm="titleForm"
        @fnBackLastPage="fnBackLastPage"
      ></zdzpForm>
    </basic-container>
  </div>
</template>

<script>
import zdfqForm from "@/views/hetongrenwu/components/zhongdianfq-form.vue";
import zdzpForm from "@/views/hetongrenwu/components/zhongdianzp-form.vue";
import {
  fetchList,
  sent,
  checkIsOne,
  getScore,
} from "@/api/hetongrenwu/zhongdian/renwutianbao";
import { getObj,getRwPlFaqiCount } from "@/api/hetongrenwu/zhongdian/renwuchuangjian";
import { radioTwoList } from "@/api/hetongrenwu/hetonghtxxdjb";
import { validatenull } from "@/util/validate";
export default {
  components: {
    zdfqForm,
    zdzpForm,
  },
  data() {
    return {
      optionsStatus: [
        {
          value: 0,
          label: "未发起",
        },
        {
          value: 1,
          label: "已发起",
        },
        {
          value: 2,
          label: "已自评",
        },
        {
          value: 3,
          label: "已评价",
        },
        {
          value: 4,
          label: "已汇总",
        },
      ],
      titleForm: {},
      showZhong: 1,
      dataForm: {},
      radio: "1",
      radioTwo: "1",
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataList: [],
      dataListLoading: false,
      searchadvanced: true,
      searchheight: "0",
      radioTwoList: radioTwoList,
      tableShow: true,
      showType: 1,
    };
  },
  created() {
    let params = this.$route.query;
    if (!validatenull(params)) {
      this.radioTwo = params.radioTwo;
    }
    this.getDataList();
  },
  methods: {
    searchchangeadvanced() {
      this.searchadvanced = !this.searchadvanced;
      if (this.searchadvanced) {
        this.searchheight = "auto";
      }
    },
    //预览
    preview(row) {
      getObj(row.id).then((res) => {
        row.start = res.data.data.rwYxqq;
        row.end = res.data.data.rwYxqz;
        getScore({ id: row.id }).then((res) => {
          this.titleForm = row;
          this.showZhong = 2;
          this.$nextTick(() => {
            var data = {
              dataForm: {
                dataList: res.data.data,
              },
              showTextarea: "faqi",
            };
            this.$refs.renwufaqi.init(data);
          });
        });
      });
    },
    getDataList() {
      this.dataListLoading = true;
      fetchList(
        Object.assign(
          {
            current: this.pageIndex,
            size: this.pageSize,
          },
          this.dataForm
        )
      ).then((response) => {
        this.dataList = response.data.data.records;
        this.totalPage = response.data.data.total;
        this.dataListLoading = false;
      });
    },
    switchBtn(e) {
      this.showType = e;
      this.tableShow = false;
      this.$nextTick((res) => {
        this.tableShow = true;
      });
    },
    //任务考核返回数据
    fnBackLastPage(data) {
      if (data == "返回原页面") {
        this.showZhong = 1;
      }
    },
    sent() {
      var data = this.$refs.table.selection;
      if(data.length==0){
        this.$message.warning('请选择发起的数据!')
        return false
      }
     var ids=[]
      if(data.length>0){
        data.forEach(item => {
          ids.push(item.id)
        });
      }
      var params={
        cjid:ids
      }
      getRwPlFaqiCount(params).then(res=>{
        if(res.data.data){
          var that=this;
          this.$confirm(res.data.data, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            that.fnsent(data)
          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消'
            });
          });
        }else{
           this.fnsent(data)
        }

      })

    },
    fnsent(data){
      checkIsOne({rows:data}).then(res=>{
        if(res.data.data){
          sent(data).then((res) => {
            if (res) {
              this.$message({
                type: "success",
                message: "发起成功!",
              });
              this.getDataList();
            } else {
              this.$message({
                type: "error",
                message: "发起失败!",
              });
            }
          });
        }else{
          this.$message.warning("请等待其他批次完成任务下达")
        }
      })

    },
    checkboxSelect(row, rowIndex) {
      if (row.state == "12") {
        return true;
      } else {
        return false;
      }
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    },
  },
};
</script>

<style>
</style>
